trait CorePackage {
	case class Point(val x :Int, val y :Int)
}

trait TextViewBasePackage
{
	type TTextView <: TextViewBase
	
	def TextView(name :String, x :Int, y :Int, w :Int, h:Int) :TTextView 
	class TextViewBase(val name :String, val x :Int, val y :Int, val w :Int, val h:Int) requires TTextView{
		def origin = Pair(x,y)
		def size = Pair(w,h)
	}
}

trait ShapeBasePackage requires (CorePackage with ShapeBasePackage) {
	type TShape <: ShapeBase
	trait ShapeBase requires TShape {
		def boundingBox :Pair[Point, Point]
		def circumference = {
			val Pair(Point(x1, y1), Point(x2, y2)) = boundingBox
			2*((x2-x1)+(y2-y1))
		} 	
	}
}

trait TextViewShapeAdapterPackage requires (CorePackage with  with ShapeBasePackage with TextViewBasePackage with  ) {
	type TTextView <: TShape with TextViewShapeAdapter

	class TextViewShapeAdapter(val name :String, val x :Int, val y :Int, val w :Int, val h:Int) requires TTextView extends TextViewBase(name, x, y, w, h)  with ShapeBase {
		def boundingBox = Pair(Point(x,y), Point(x+w, y+h))		
	}
}

class Deployment extends CorePackage with TextViewBasePackage
                                      with ShapeBasePackage[Deployment]
                                      with TextViewShapeAdapterPackage[Deployment]  {
    type TTextView = TextViewShapeAdapter
 	type TShape = ShapeBase

	def TextView(name :String, x :Int, y :Int, w :Int, h:Int) :TTextView = new TextViewShapeAdapter(name, x, y, w, h) 	
}

object Main extends Deployment {
	def main(args :Array[String]) = System.out.println(TextView("foo", 0, 0, 10, 10).circumference)
}

       